package com.yunduo.world.worker;

import com.yunduo.world.constant.NetWorkConstant;
import com.yunduo.world.entity.EntityInfo;
import com.yunduo.world.factory.ChannelWorker;
import com.yunduo.world.utils.ClientUtils;
import com.yunduo.world.utils.EntityBuild;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * 异常连接
 */
@Slf4j
public class ThrowWorker extends ChannelWorker {
    @Override
    public void execute() {
        log.info("未知消息");
        EntityInfo.Entity data = EntityBuild.buildMessage(NetWorkConstant.NET_WORK, "未知消息，已强制下线", NetWorkConstant.NOT_OK);
        getCtx().writeAndFlush(data);
        ReferenceCountUtil.release(getMsg());
        ClientUtils.removeChannel(getCtx().channel());
    }
}
